#include "head.h"
int global_thread_num;
int global_server_log_fd;
char global_ip[20];
char global_port[20];

static void get_config(char *name, char *key){
    FILE *fp = fopen("config.ini", "r");
    ERROR_CHECK(fp, NULL, "fopen_getConfig.ini");

    char buf[100] = { 0 };
    while(fgets(buf, sizeof(buf), fp) != NULL){
        char *p = strtok(buf, "=");
        if(strcmp(p, name) == 0){
            p = strtok(NULL, "\n");
            strcpy(key, p);
        }
    }

}



int config_init(){
    get_config("global_ip", global_ip);
    get_config("global_port", global_port);

    printf("ip: %s  port:%s\n", global_ip, global_port);
    char buf[100];
    get_config("global_thread_num", buf);
    global_thread_num = atoi(buf);
    printf("num:%d\n", atoi(buf));
    
    bzero(buf, sizeof(buf));
    get_config("global_server_log_fd", buf);
    printf("path:%s\n", buf);
    int global_server_log_fd = open(buf, O_WRONLY|O_APPEND);
    ERROR_CHECK(global_server_log_fd, -1, "open_getConfig.c");
    return 0;
}
